/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package btracker;


import java.awt.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author Sammy
 */
public class Loader {

    public static void gui() throws InterruptedException{
Login.pnlTextField.removeAll();



        JProgressBar prBar = new JProgressBar();
        JLabel lblLogin = new JLabel();
        JFrame load = new JFrame();
        boolean loading = true;

        load.setVisible(true);
        load.setSize(300, 80);
        load.setLocationRelativeTo(null);


        load.add(BorderLayout.PAGE_END, prBar);
        load.add(BorderLayout.CENTER,lblLogin);

        lblLogin.setFont(new Font("Arial", 0, 20));
        int n = 0;
        while (loading) {
            lblLogin.setText("            LOGING IN");
            Login.loginFrame.setVisible(false);
            prBar.setValue( n = n + 20);
            try {
                StoredData.getDataFromFiles();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
            }
            Thread.sleep(50);
            lblLogin.setText("            LOGING IN.");
            prBar.setValue(n = n + 20);
            Thread.sleep(50);
            lblLogin.setText("            LOGING IN..");
            prBar.setValue(n = n + 20);
            Thread.sleep(50);
            lblLogin.setText("            LOGING IN...");
            prBar.setValue(n = n + 20);
             if (n >= 100) {
                loading = false;
            }
        }
        try {
            MainWindow.mainGUI();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Loader.class.getName()).log(Level.SEVERE, null, ex);
        }

        MainWindow.mainFrame.setVisible(true);
        load.setVisible(loading);
        
    }
}
